#include<iostream>

using namespace std;
const int N=100010;

int p[N]={0},sz[N]={0};
int n,m;

int find(int x)
{
    if(p[x]!=x) p[x]=find(p[x]);
    return p[x];
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i) 
    {
        p[i]=i;
        sz[i]=1;
    }
    while(m--)
    {
        int a,b;
        char ch[5];scanf("%s",ch);
        if(ch[0]=='C')
        {
            scanf("%d%d",&a,&b);
            if(find(a)==find(b)) continue;
            sz[find(b)]+=sz[find(a)];
            p[find(a)]=find(b);
        }
        else if(ch[1]=='1')
        {
            scanf("%d%d",&a,&b);
            if(find(a)==find(b)) cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
        }
        else
        {
            scanf("%d",&a);
            cout<<sz[find(a)]<<endl;
        }
    }
    return 0;
}